<template>
    <div>
        <list-table ref="listTable" @showDialog="showDialog" v-bind="$attrs" v-on="$listeners"></list-table>
        <create-document-dialog ref="myDialog" :visible.sync="visible" v-if="visible" :row="currRow" @reloadList="query"></create-document-dialog>
        <detail-document-dialog :visible.sync="detailVisible" v-if="detailVisible" :row="currRow" @reloadList="query"></detail-document-dialog>
    </div>
</template>
<script>
    import CreateDocumentDialog from "../../../components/WorkFlowsDialog/CreateDocumentDialog";
    import ListTable from "../components/ListTable";
    import LeftForm from "./LeftForm";
    import MyWord from "@/components/WorkFlowsDialog/DocumentCase/MyWord";
    import IssueViewDialog from "../../../components/WorkFlowsDialog/DocumentCase/IssueViewDialog";
    import AttachmentsList from "../../../components/WorkFlowsDialog/DocumentCase/AttachmentsList";
    import PreviewFile from "@/components/Common/PreviewFile";
    import openDialog from "@/mixins/openDialog";
    import isSelectApprover from "@/mixins/isSelectApprover";
    import schoolSignature from "@/api/officialDocument/schoolSignature/index";
    import ApproverList from "@/components/WorkFlowsDialog/Case/ApproverList";
    import DetailDocumentDialog from "../../../components/WorkFlowsDialog/DetailDocumentDialog";
    export default {
        name: "TabContentIssue",
        mixins: [openDialog,isSelectApprover],
        provide(){
            return{
                key:this.$attrs.params.category
            }
        },
        components: {
          DetailDocumentDialog,
          CreateDocumentDialog,
            ApproverList,
            PreviewFile,
            AttachmentsList, MyWord, IssueViewDialog, LeftForm, ListTable, CreateDocumentDialog
        },
        data() {
            return {
                visible: false,
                detailVisible: false,
                currRow: {},
                showActiveBtn: false,
                issueViewVisible: false,
                info: {},
                title: "新建",
                previewVisible: false
            }
        },
        created() {
        },
        computed: {
            type_id() {
                let path = this.$route.fullPath.split("/")
                let key = path[path.length - 1]
                return key == "schoolDocuments" ? 3 : 4
            },
        },
        methods: {
            showPreview() {
                this.previewVisible = true
            },
            query() {
                this.$refs["listTable"].getList();
            },
            showDialog(row, type) {
                if (row.id) {
                    schoolSignature.getDocumentById(row.id).then(res => {
                        this.currRow = res.data
                        if (type == "handle") {
                            this.showActiveBtn = true
                            this.detailVisible = true
                        } else if (type == 'view') {
                            this.showActiveBtn = false
                            this.detailVisible = true
                        } else if (type == "edit") {
                            this.visible = true
                        }
                    })
                } else {
                    this.currRow = {}
                    this.visible = true
                }
            },
            showApproverOrSubmit(data, is_draft, flag = true) {
                data.is_draft = is_draft
                this.info = data
                //      this.info.dist = data.send_dept.join(",")
                if (is_draft == 0 && flag) {
                    this.getDeptListById()
                } else {
                    this.$refs['myDialog'].toSubmit(this.info)
                }
            },
            createSubmit(is_draft, flag) {
                this.$refs['leftForm'].submitForm().then(data => {
                    if(is_draft==2){
                        this.$refs['myDialog'].editDocumentSave(data)
                    }
                    else if(data.is_edit){
                        this.$refs['myDialog'].toSubmit(data)
                    }
                    else{
                         data.is_draft = is_draft
                        this.info = data
                         this.getIsSelect('xxfw',()=>{this.$refs['myDialog'].toSubmit(data)})
                    }
                })
            },
        }
    }
</script>
